<?php

/**
 * Model base class.
 *
 * @version  $Id: model.php 2 2009-10-02 23:06:43Z perfilev $
 * @package  System
 */

abstract class Model
{
	/**
	 * Factory.
	 *
	 * @param  string  $name  Model class name.
	 * @return object
	 */
	public static function factory($name)
	{
		$name = 'Model_' . $name;
		return new $name;
	}

	/**
	 * @var Database Database object.
	 */
	protected $db = 'default';
	
	/**
	 * Loads the database instance, if the database is not already loaded.
	 *
	 * @return  void
	 */
	public function __construct()
	{
		if (!is_object($this->db)) {
			$this->db = Database::instance($this->db);
		}
	}
}
